package com.yicoollxing.controller.backend;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yicoollxing.common.Const;
import com.yicoollxing.common.ServerResponse;
import com.yicoollxing.pojo.User;
import com.yicoollxing.service.IOrderService;
import com.yicoollxing.service.IUserService;


@Controller
@RequestMapping("/manager/order")
public class OrderManagerController {
   //订单列表，订单查询，订单详情
	
	@Autowired
	private IUserService iUserService;
	
	@Autowired
	private IOrderService iOrderService;
	
	
	@ResponseBody
	@RequestMapping("/list.do")
	public ServerResponse list(@RequestParam(value="pageNum",defaultValue="1")Integer pageNum,
			@RequestParam(value="pageNum",defaultValue="5")Integer pageSize,Integer mid,HttpSession session){
	
		User user = (User) session.getAttribute(Const.CURRENT_USER);
		if (user == null) {
			return ServerResponse.createByErrorMessage("请重新登录");
		}
		ServerResponse response = iUserService.checkAdminRole(user);
		if (!response.isSuccess()) {
			return response;
		}
		return iOrderService.list(pageNum, pageSize, mid);
	}
	
	
	@ResponseBody
	@RequestMapping("/detial.do")
	public ServerResponse detial(Integer orderId,HttpSession session){

		User user = (User) session.getAttribute(Const.CURRENT_USER);
		if (user == null) {
			return ServerResponse.createByErrorMessage("请重新登录");
		}
		ServerResponse response = iUserService.checkAdminRole(user);
		if (!response.isSuccess()) {
			return response;
		}
		
		return iOrderService.detail(orderId);
	}
	
	@ResponseBody
	@RequestMapping("/serach.do")
	public ServerResponse serach(Integer orderNo,HttpSession session){

		User user = (User) session.getAttribute(Const.CURRENT_USER);
		if (user == null) {
			return ServerResponse.createByErrorMessage("请重新登录");
		}
		ServerResponse response = iUserService.checkAdminRole(user);
		if (!response.isSuccess()) {
			return response;
		}
		
		return iOrderService.serach(orderNo);
	}
	
	
}
